/****************************************************************************
 * Copyright (c) 2010 Torkild U. Resheim
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Torkild U. Resheim  - initial API and implementation
 *****************************************************************************/
package no.resheim.buildmonitor.hudson;

import java.net.URI;

import no.resheim.buildmonitor.core.IServerFactory;
import no.resheim.buildmonitor.core.data.Server;

import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.ContainerFactory;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.ui.dialogs.IDCreateErrorDialog;

public class HudsonServerFactory implements IServerFactory {

	@Override
	public Server createInstance(URI uri) {
		IContainer container = null;
		try {
			container = ContainerFactory.getDefault().createContainer(
					"ecf.rest.client", uri.toString());
			return new HudsonServer(container, uri);
		} catch (final IDCreateException e) {
			new IDCreateErrorDialog(null, uri.toString(), e).open();
		} catch (ContainerCreateException e) {
			e.printStackTrace();
		}
		return null;
	}
}
